package cn.acewill.yxd.yunxundian.ui.user;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;

import com.xiao.nicevideoplayer.NiceVideoPlayer;
import com.xiao.nicevideoplayer.NiceVideoPlayerManager;
import com.xiao.nicevideoplayer.TxVideoPlayerController;

import cn.acewill.yxd.yunxundian.BaseActivity;
import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/9/15.
 */

public class ToolVideoPlayActivity extends BaseActivity{


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toolvideo_paly);
        NiceVideoPlayer player = (NiceVideoPlayer) findViewById(R.id.player);
        String path = getIntent().getStringExtra("path");
        String name = getIntent().getStringExtra("name");
        player.setPlayerType(NiceVideoPlayer.TYPE_NATIVE);
        player.setUp(path,null);
        TxVideoPlayerController controller = new TxVideoPlayerController(this);
        controller.setTitle(name);
        player.setController(controller);
        player.setBackgroundColor(Color.BLACK);
        //缺陷，视频缩略图加载有问题
    }

    @Override
    protected void onStop() {
        super.onStop();
        // 在onStop时释放掉播放器
        NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
    }
    @Override
    public void onBackPressed() {
        // 在全屏或者小窗口时按返回键要先退出全屏或小窗口，
        // 所以在Activity中onBackPress要交给NiceVideoPlayer先处理。
        if (NiceVideoPlayerManager.instance().onBackPressd()) return;
        super.onBackPressed();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK){
            NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
        }
        return super.onKeyDown(keyCode, event);
    }
}
